# -*- conding:UTF-8 -*-

'''
@ Project: P8_lxpro_7.7
@ File: users.py
@ Author: 罗婷
@ Date：2022/7/7 14:04

'''
import random
from datetime import datetime

from common.models import db




# 用户  1
class Users(db.Model):
    __tablename__ = 'tb_user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc="用户ID")
    motto = db.Column(db.String(32), doc="座右铭", default='')
    nickname = db.Column(db.String(32), doc="用户名")
    mobile = db.Column(db.String(11), doc="手机号")
    password = db.Column(db.String(256), doc="密码")
    email = db.Column(db.String(65), doc="邮箱", default='')
    avatar = db.Column(db.String(562), doc="头像", default='')
    gender = db.Column(db.Integer, doc="0 男，1 女")
    online = db.Column(db.Integer, doc="0未上线，1 在线",)
    # friend_id = db.relationship('Group', backref='group_user', secondary='tb_user_group')

# 申请表
class Friends(db.Model):
    __tablename__ = 'tb_friends'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc="中间ID")
    user_id = db.Column(db.Integer, db.ForeignKey('tb_user.id'),  doc="用户ID")
    friend_id = db.Column(db.Integer, db.ForeignKey('tb_user.id'),  doc="好友ID")
    is_follow = db.Column(db.Boolean, doc='是否同意好友申请')
    created_at = db.Column(db.DateTime, default=datetime.now(), doc='申请时间')
    remark = db.Column(db.String(32), doc="申请备注", default='')

# 群成员
class GroupMember(db.Model):
    __tablename__ = 'tb_groupmember'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True, doc='群成员id')
    user_id = db.Column(db.Integer, db.ForeignKey('tb_user.id'), doc='用户id')
    leader = db.Column(db.Integer, doc='用户属性 0普通 1管理员 2 群主', default=0)
    is_mute = db.Column(db.Integer, default=0, doc='是否禁言1是 0 否')
    is_quit = db.Column(db.Integer, default=0, doc='是否退群1是 0 否')
    user_card = db.Column(db.String(100), default='', doc='群名片')
    created_at = db.Column(db.DateTime, default=datetime.now(), doc='入群时间', nullable=True)
    updated_at = db.Column(db.DateTime, default=datetime.now(), doc='更新时间', nullable=True)
    delete_at = db.Column(db.DateTime, doc='退群时间', nullable=True)
    # group_id = db.Column(db.Integer, db.ForeignKey('tb_group.id'), doc='群id')
#
# 群与组员的中间表
class User_Group(db.Model):
    __tablename__ = 'tb_member_group'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='id')
    mid = db.Column(db.Integer, db.ForeignKey('tb_groupmember.id'), doc='群成员')
    group_id = db.Column(db.Integer, db.ForeignKey('tb_group.id'))


# 群
class Group(db.Model):
    __tablename__ = 'tb_group'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='群id')
    creator_id = db.Column(db.Integer, doc='群主id')
    group_name = db.Column(db.String(33), default='', doc='群名')
    profile = db.Column(db.String(100), default='', doc='群介绍')
    avatar = db.Column(db.String(200), default='', doc='群头像')
    max_num = db.Column(db.Integer, default=200, doc='最大群员数量')
    is_overt = db.Column(db.Integer, default=0, doc='是否公开课件1是 0 否')
    is_mute = db.Column(db.Integer, default=0, doc='是否全员禁言1是 0 否')
    is_dismiss = db.Column(db.Integer, default=0, doc='是否已解散1是 0 否')
    created_at = db.Column(db.DateTime, default=datetime.now(), doc='创建时间', nullable=True)
    updated_at = db.Column(db.DateTime, default=datetime.now(), doc='更新时间', nullable=True)
    dismissed_at = db.Column(db.DateTime, doc='解散时间', nullable=True)
    # member_id = db.relationship('GroupMember', backref='member_group')
    # 关系字段添加时需要 列表套对象 [对象1, 对象2]   不是int
    member = db.relationship('GroupMember', secondary='tb_member_group',backref='member_group')
















